package cn.web.auction.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.web.auction.pojo.Pcomment;
import cn.web.auction.service.PcommentService;
import cn.web.auction.util.Result;
import net.sf.json.JSONArray;


@Controller
public class PcommentController {
	@Autowired
	private PcommentService pcommentservice;
	//显示查询,显示评论表里的数据
	@CrossOrigin
	@ResponseBody
	@RequestMapping("/queryPcomment")
	public Object queryPcomment() {
		List<Pcomment> list = pcommentservice.findComment();
		JSONArray jsonstr = JSONArray.fromObject(list);
		System.out.print(jsonstr);
		return Result.success(jsonstr);
		
	}
	
	//添加评论，点赞数据
	@CrossOrigin
	@ResponseBody
	@RequestMapping("/addPcomment")
	public Object addPcomment(Pcomment pcomment) {
		System.out.println("running"+pcomment+"");
		pcommentservice.addComment(pcomment);
		JSONArray jsonstr = JSONArray.fromObject(pcomment);
		System.out.println(jsonstr);
		return Result.success(jsonstr);
	}
	
	//添加点赞数据
	@CrossOrigin
	@ResponseBody
	@RequestMapping("/updatePcomment")
	public Object updatePcomment(Pcomment pcomment) {
		pcommentservice.updateComment(pcomment);
		JSONArray jsonstr = JSONArray.fromObject(pcomment);
		System.out.println(jsonstr);
		return Result.success(jsonstr);
	}

}
